package com.ruoyi.system.domain;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;


/**
 * 【请填写功能名称】对象 health_device
 * 
 * @author 22008021011æ¯ä½³é¹
 * @date 2025-06-17
 */

@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
public class Device extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 设备ID */
    private String sn;

    /** 时间戳 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "时间戳", width = 30, dateFormat = "yyyy-MM-dd")
    private Date realDatatime;

    /** 电量 */
    @Excel(name = "电量")
    private Long battery;

    /** 信号量 */
    @Excel(name = "信号量")
    private Long rssi;

    /** 当日累计步数 */
    @Excel(name = "当日累计步数")
    private Long step;

    /** 当日移动距离 */
    @Excel(name = "当日移动距离")
    private BigDecimal distance;

    /** 当日运动卡路里 */
    @Excel(name = "当日运动卡路里")
    private BigDecimal calorie;

    private Date date;


    /** 日期 */
    public Device(JSONObject data) {
        this.setSn((String) data.get("sn"));
        Date date = new Date();
        try {
            String dateString = (String) data.get("dateTime");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            date = sdf.parse(dateString);
        } catch (ParseException e) {
            //do nothing
        }
        this.setRealDatatime(date);
        this.setStep(Long.valueOf(data.get("step").toString()));
        this.setBattery(Long.valueOf(data.get("battery").toString()));
        this.setRssi(Long.valueOf(data.get("rssi").toString()));
        this.setCalorie((BigDecimal) data.get("calorie"));
        this.setDistance((BigDecimal) data.get("distance"));
        this.setDate(date) ;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("sn", getSn())
            .append("realDatatime", getRealDatatime())
            .append("battery", getBattery())
            .append("rssi", getRssi())
            .append("step", getStep())
            .append("distance", getDistance())
            .append("calorie", getCalorie())
            .append("date", getDate())
            .toString();
    }
}
